using UnityGameFramework.Runtime;

namespace LS.UGFUnits
{
    using Unity.VisualScripting;
    
    public class AttachEntity_Instance : EntityUnit
    {
        [DoNotSerialize]
        public ValueInput Child { get; set; }
                
        [DoNotSerialize]
        public ValueInput Parent { get; set; }
        
        protected override void Definition()
        {
            base.Definition();
            Child = ValueInput<Entity>(nameof(Child));
            Parent = ValueInput<Entity>(nameof(Parent));
            Requirement(Parent, Input);
            Requirement(Child, Input);
        }

        protected override ControlOutput In(Flow flow)
        {
            Entity child = flow.GetValue<Entity>(Child);
            Entity parent = flow.GetValue<Entity>(Parent);
            Target?.AttachEntity(child, parent);
            return base.In(flow);
        }
    }
    public class AttachEntity_Id : EntityUnit
    {
        [DoNotSerialize]
        public ValueInput Child { get; set; }
                
        [DoNotSerialize]
        public ValueInput Parent { get; set; }
        
        protected override void Definition()
        {
            base.Definition();
            Child = ValueInput<int>(nameof(Child));
            Parent = ValueInput<int>(nameof(Parent));
            Requirement(Parent, Input);
            Requirement(Child, Input);
        }

        protected override ControlOutput In(Flow flow)
        {
            int child = flow.GetValue<int>(Child);
            int parent = flow.GetValue<int>(Parent);
            Target?.AttachEntity(child, parent);
            return base.In(flow);
        }
    }
    
    public class AttachEntity_Instance_Id : EntityUnit
    {
        [DoNotSerialize]
        public ValueInput Child { get; set; }
                
        [DoNotSerialize]
        public ValueInput Parent { get; set; }
        
        protected override void Definition()
        {
            base.Definition();
            Child = ValueInput<Entity>(nameof(Child));
            Parent = ValueInput<int>(nameof(Parent));
            Requirement(Parent, Input);
            Requirement(Child, Input);
        }

        protected override ControlOutput In(Flow flow)
        {
            Entity child = flow.GetValue<Entity>(Child);
            int parent = flow.GetValue<int>(Parent);
            Target?.AttachEntity(child, parent);
            return base.In(flow);
        }
    }
    
    public class AttachEntityLogic_Instance_Id : EntityUnit
    {
        [DoNotSerialize]
        public ValueInput Child { get; set; }
                
        [DoNotSerialize]
        public ValueInput Parent { get; set; }
        
        protected override void Definition()
        {
            base.Definition();
            Child = ValueInput<EntityLogic>(nameof(Child));
            Parent = ValueInput<int>(nameof(Parent));
            Requirement(Parent, Input);
            Requirement(Child, Input);
        }

        protected override ControlOutput In(Flow flow)
        {
            EntityLogic child = flow.GetValue<EntityLogic>(Child);
            int parent = flow.GetValue<int>(Parent);
            Target?.AttachEntity(child.Entity, parent);
            return base.In(flow);
        }
    }
}